package com.malty.mall.controller.pms;

import com.malty.mall.common.CommonResult;
import com.malty.mall.domain.dto.req.pms.PmsProductParam;
import com.malty.mall.domain.dto.req.pms.PmsProductParam;
import com.malty.mall.domain.entity.pms.PmsProduct;
import com.malty.mall.service.pms.IPmsProductAttributeCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author malty
 */
@RestController
@Api(tags = "属性分类管理")
@RequestMapping("/product/attribute/category")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class PmsProductController {
    private final IPmsProductAttributeCategoryService attributeCategoryService;

    @PostMapping("/create")
    @ApiOperation("创建属性分类")
    public CommonResult<Boolean> create(@RequestBody @Validated PmsProductParam productParam) {
        return CommonResult.success(attributeCategoryService.create(productParam));
    }

    @PostMapping("/update")
    @ApiOperation("编辑属性分类")
    public CommonResult<Boolean> update(@RequestBody @Validated PmsProductParam productParam) {
        return CommonResult.success(attributeCategoryService.updateCategoryById(productParam));
    }

    @GetMapping("/{id}")
    @ApiOperation("查询属性分类")
    public CommonResult<PmsProductParam> queryById(@PathVariable Integer id) {
        return CommonResult.success(attributeCategoryService.queryCateById(id));
    }

    @GetMapping("/list_")
    @ApiOperation("查询所有属性分类")
    public CommonResult<List<PmsProductParam>> list(Integer pageNum, Integer pageSize) {
        return CommonResult.success(attributeCategoryService.list(pageNum, pageSize));
    }

    @GetMapping("/list/with_attr")
    @ApiOperation("获取所有商品属性分类及其下属性")
    public CommonResult<List<PmsProductParam>> listWithAttr() {
        return CommonResult.success(attributeCategoryService.listWithAttr());
    }

    @ApiOperation("删除属性分类")
    @GetMapping("/delete/{id}")
    public CommonResult<Boolean> queryById(@PathVariable Long id) {
        return CommonResult.success(attributeCategoryService.deleteById(id));
    }
}
